GenerativeComponents Help

The DataConnection Class

A DataConnection represents an open database session. Typically, the first step in accessing a database is to create a DataConnection object, and the last step is to call the Close() method on that object.

Not every database session requires a DataConnection object. In particular, an XML data set file can be accessed simply by creating a DataTable object, without a DataConnection.

Here are the constructors, properties and methods of the DataConnection class:

new DataConnection(databaseType, filePath)

Generally, this constructor is for connecting to a database that resides in a single file on your local computer; for example, an Access database.

The arguments are:

DatabaseType databaseType

The type of the database. One of the enumerated values Access, CommaSeparatedText, or SqlServerLocalDB. (A CommaSeparatedText database is a plain text file in which the first line comprises a list of column names separated by commas, and each of the remaining lines comprises a list of values separated by commas.)

string filePath

The full path and file name of the database file. (Remember that you can enter this value by using the Expression Builder's file browser.) (In the case of CommaSeparatedText, only the directory portion of this path is used.)

new DataConnection(connectionType, connectionString)

Generally, this constructor is for connecting to a database that doesn't reside on your local computer, and/or has a different file format than is supported by the other constructor. This constructor provides the greatest degree of power and flexibility, but also requires the greatest level of expertise on the part of the user.

The arguments are:

DataConnectionType connectionType

One of the enumerated values Odbc, OleDb, or SqlClient.

string connectionString

A connection string that is valid to an ADO.NET data connection object of the specified connection type. For more information, please consult documentation for Microsoft's ADO.NET.

void Close()

This method closes the data connection. This should always be the last thing you do when you're working with a database.

string ConnectionString { get; }

This read-only property returns the connection string, for informational or diagnostic purposes.

Every DataConnection object has a connection string, whether it was given to the constructor or formulated internally.